package sql;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.List;

import arbre.utils.Chemin;
import arbre.utils.Polyedre;
import arbre.utils.Segment;

public class Writor {

	public static void ecrire(String nomFichier,String contenu) {
		File fichier = new File(nomFichier);

		try {
			BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fichier),"UTF-8"));
			out.write(contenu);
			out.close();
		}
		catch (IOException ie)
		{
			ie.printStackTrace(); 
		}

	}

	public static String toMap(List<Polyedre> polyedres, List<Chemin> chemins){
		StringBuffer sb = new StringBuffer();

		sb.append("<map>\n");

		if(polyedres != null)
			for(Polyedre p : polyedres){
				sb.append(p.toXml());
			}
		if(chemins != null)
			for(Chemin c : chemins){
				sb.append(c.toString());
			}

		sb.append("</map>\n");

		return sb.toString();
	}

}
